package model;

import java.sql.*;
import java.util.*;

/**
 * Class that handles the connection to the database.
 * This class MUST be used everytime you need to connect to the db to submit a query.
 * @author Francesco Anderloni
 * @version 5
 */
public class ConnectionManager {

	static Connection con;
	static String url;

	/**
	 * This methods open the connection.
	 * ATTENTION: the connection must be closed at the end of the calling method.
	 * @return A Connection object.
	 */
	public static Connection getConnection()
	{
		try
		{
			String url = "jdbc:postgresql://" + "localhost:5432/PIP"; 
			// The database URL
			Class.forName("org.postgresql.Driver");
			try
			{            	
				con = DriverManager.getConnection(url,"pip","jiutuebe"); 
				// "pip" is our username and "jiutuebe" our password on the Uni's server
			}
			catch (SQLException ex)
			{
				ex.printStackTrace();
			}
		}
		catch(ClassNotFoundException e)
		{
			System.out.println(e);
		}
		return con;
	}
}